package com.itstack.springframework.test.processor;

import com.itstack.springframework.beans.BeansException;
import com.itstack.springframework.beans.factory.config.BeanPostProcessor;
import com.itstack.springframework.test.bean.UserService;

/**
 * ClassName:
 * Description: TODO
 *
 * @author: Guo Shuai
 * @version: 1.0
 * @Date: 2021\11\25 0025
 */
public class UserServiceBeanPostProcessor implements BeanPostProcessor {


    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof UserService) {
            UserService userService = (UserService) bean;
            userService.setId(2L);
        }

        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}
